<template>
  <div>
    <kendoForm :kendo-form-items="kendoFormItems" :kendo-form="kendoForm" :kendo-params-value="kendoParamsValue" :kendo-data-sources="kendoDataSources" />
  </div>
</template>

<script>
  import kendoForm from '@/Views/components/kendo-vue-component/kendoForm/index.vue'
  export default {
    name: 'DictOperate',
    components: {
      kendoForm
    },
    data() {
      return {
        dialogName: this.$attrs.data.dialogName,
        kendoFormItems: [
          {
            name: 'dictTp',
            label: '字典类型',
            paramName: 'dictTp',
            required: true,
            controlType: 'input'
          },
          {
            name: 'dictTpNm',
            label: '字典类型名称',
            paramName: 'dictTpNm',
            required: true,
            controlType: 'input'
          },
          {
            name: 'dictKey',
            label: '字典键',
            paramName: 'dictKey',
            required: true,
            controlType: 'input'
          },
          {
            name: 'dictVal',
            label: '字典值',
            paramName: 'dictVal',
            required: true,
            controlType: 'input'
          },
          {
            name: 'dictValNm',
            label: '字典值名称',
            paramName: 'dictValNm',
            required: true,
            controlType: 'input'
          },
          {
            name: 'parentDictVal',
            label: '父字典值',
            paramName: 'parentDictVal',
            controlType: 'input'
          },
          {
            name: 'dictGroup',
            label: '字典组',
            paramName: 'dictGroup',
            controlType: 'input'
          },
          {
            remoteData: false,
            filter: 'contains',
            dataMapping: {
              label: 'dictValNm',
              value: 'dictVal'
            },
            dataSourceName: 'STATUS_CD',
            name: 'dictStatus',
            label: '字典状态',
            paramName: 'dictStatus',
            required: true,
            controlType: 'dropDownList'
          },
          {
            name: 'dictSeq',
            label: '字典顺序',
            paramName: 'dictSeq',
            required: true,
            controlType: 'numeric'
          },
          {
            genre: 'special',
            label: '字典描述',
            name: 'dictDesc',
            paramName: 'dictDesc',
            controlType: 'textarea'
          }
        ],
        kendoForm: {
          ref: 'prodForm',
          valid: 'valid',
          buttons: [
            {
              name: '保存', // 按钮内容
              class: 'k-primary', // 按钮样式
              icon: 'save',
              click: this.save
            },
            {
              name: '重置', // 按钮内容
              icon: 'reset-sm',
              click: this.reset
            }
          ],
          rules: {},
          message: {}
        },
        kendoParamsValue: {
          dictTp: '',
          dictTpNm: '',
          dictKey: '',
          dictVal: '',
          dictValNm: '',
          parentDictVal: '',
          dictStatus: '',
          dictGroup: '',
          dictDesc: ''
        },
        kendoDataSources: {
          STATUS_CD: [
            { dictValNm: '有效', dictVal: '1' },
            { dictValNm: '无效', dictVal: '0' }
          ]
        }
      }
    },
    mounted() {
      this.kendoParamsValue = Object.assign(this.kendoParamsValue, this.$attrs.data.param)
    },
    methods: {
      save(paramVal, validator) {
        if (validator.validate()) {
          this.$post('/service/sysMng/dict/saveDictInfo', paramVal).then(res => {
            if (res.code !== 200) {
              this.$KendoNotify({
                title: '错误信息:' + res.code,
                message: res.message
              }, 'error')
            } else {
              this.$KendoNotify({
                title: '提示信息:',
                message: res.message
              }, 'success')
              this.$bus.emit('dialog' + `${this.dialogName}`, true)
            }
          })
        }
      },
      reset(paramVal) {
        Object.keys(paramVal).forEach(key => {
          if (Array.isArray(paramVal[key])) {
            this.kendoParamsValue[key] = []
          } else {
            this.kendoParamsValue[key] = ''
          }
        })
      }
    }
  }
</script>

<style>

</style>
